home *** CD-ROM | disk | FTP | other *** search
- Path: kuhub.cc.ukans.edu!anh
- From: anh@kuhub.cc.ukans.edu
- Newsgroups: comp.lang.c
- Subject: Re: Tradition or what?
- Message-ID: <1996Mar16.172511.116133@kuhub.cc.ukans.edu>
- Date: 16 Mar 96 17:25:11 CST
- References: <4g0elg$mdr@redstone.interpath.net> <4hpd8a$d70@alterdial.UU.NET> <314ac1ef.49220064@nntp.ix.netcom.com>
- Organization: University of Kansas Academic Computing Services
-
- I agree. The sizeof() just slipped my mind when I typed this in. :-)
-
- Anh
-
- In article <314ac1ef.49220064@nntp.ix.netcom.com>, miker3@ix.netcom.com (Mike Rubenstein) writes:
- > anh@kuhub.cc.ukans.edu wrote:
- >
- >> Well, I found one good use of magic numbers such as when one needs a
- >> localized temporary buffer of data.
- >>
- >> int func()
- >> {
- >> FILE *fp;
- >> char buf[15+1];
- >>
- >> ...
- >>
- >> fgets(buf,15,fp);
- >> }
- >>
- >>
- >> Well, if I know the data is always going to be less than 15 or whatever,
- >> there is really no need to use a #define here.
- >
- > Non sequitur. Whether you know that the data is going to be less than
- > 15 is immaterial. In this situration I'd very rarely use a #define
- > for the size of the buffer, but I would absolutely never repeat the
- > size as a literal later in the code. My preference is something like
- >
- > int func()
- > {
- > FILE *fp;
- > char buf[15];
- >
- > ...
- >
- > fgets(buf, sizeof buf, fp);
- > }
- >
- > Note that I've changed the size of the buffer to 15 on the assumption
- > that the intention is that the size of the data be at most 14
- > characters excluding the terminating nul.
- >
- > Michael M Rubenstein
-